Use Intent to transfer Java objects between activities in Android projects -- Implement Parcelable InterfaceUsing Intent to implement Java object transfer between activities in Android projects, there are two ways: one is the passed object implements the Serializable interface; the other is the passed object implements the Pa
WhyWhy should I understand serialization? --When doing Android development, you cannot pass the object reference to activities or fragments, we need to put these objects into a intent or bundle, and then pass them on.WhatWhat is serialization-serialization, which represents the transformation of an object into a state that can be stored or transmitted. The serialized object can be transferred on the network or stored locally.HowHow do I transfer objects by serialization?Android Intent if you wan
Understanding of Serializable and parcelable
1, the first of their two interfaces are to achieve the serialization of objects, so that it can be passed, the so-called serialization is to replace the object information can be stored in the process of media.
2, Serializable is the JDK provided by the serialization interface, the interface exists under the IO package, can be used for input and output, very simple to use, as long as your class to implem
In this paper, the serializable and Parcelable serialization objects in Android are studied in detail as follows
Learning content:
1. The purpose of serialization
Two ways to serialize in 2.Android
Performance comparison of 3.Parcelable and serializable
How to use parcelable to serialize operations in 4.Android
The working principle of 5.
Public class person implements parcelable {// member variable private int ID; private string name; // 1. parcelable must be implemented. creator interface. Otherwise, an error is returned when you obtain the person data, as shown in the following code: // android. OS. badparcelableexception: // parcelable protocol requires a
of the hard disk is the so-called virtual memory. For example, if you want to save a specific object to a file and I will use it several days later, you need to implement the Serializable interface;
B) During java Socket programming, you may sometimes want to transmit a certain type of objects, so you also need to implement the Serializable interface; the most common is that you transmit a string, it is a class in JDK and also implements the Serializ
space of the hard disk is the so-called virtual memory. For example, if you want to save a specific object to a file and I will use it several days later, you need to implement the serializable interface;B) During Java socket programming, you may sometimes want to transmit a certain type of objects, so you also need to implement the serializable interface; the most common is that you transmit a string, it is a class in JDK and also implements the ser
Both are used to support serialization, deserialization operation, the biggest difference is the storage medium, serializable use IO Read and write memory on the hard disk, and parcelable is directly read and write in RAM, it is obvious that the memory read and write speed is usually greater than IO read and write, So in Android it's usually preferred to choose parcelable.Serializable is not the focus of the current focus, but you can view the
Using self-defined parcelable objects during an Android aidl RPC/IPC callIn my previous post "Using the Android Interface Definition Language (aidl) to make a Remote Procedure call (RPC) in Andro ID "I ' ve explained the basics on how inter-process communication can is implemented in Android. Now we'll take a look at a specialized field in this area:using parcelables as parameters of a aidl method.As described in the previous post it's possible to eit
Android serialization object interface Parcelable usage method, androidparcelable
What is Parcelable?
Parcelable defines the interfaces for writing data to Parcel and reading data from Parcel. An object (represented by a class). To encapsulate it in a message, you must implement this interface to implement this interface, this entity becomes "packable.
information. Deserialization is the opposite.
Ii. What is the difference between Java object serialization and Java object serialization? The premise of a Java object must exist during the JVM runtime. If you want to obtain the specified Java object without JVM running or on the JVM of another machine, it is impossi
hard disk, and then to use the time to read into the memory, the hard disk that part of the storage space is called virtual memory. In the case of you want to save a particular object to a file, I take it out every few days, then the implementation of the Serializable interface;b) In the Java socket programming, you may sometimes want to transfer a certain class of objects, then also implement the serializable interface; the most common you transmit
data serialization and transmission. The following describes how to implement the parcelable interface.To serialize an object through the parcelable interface:
1. Implement the parcelable interface.2. Implement the public interface of the parcelable InterfaceVoid writetoparcel (parcel DEST, int flags) method.3. The
GitHub Address: Https://github.com/baoyongzhang/ParcelableGeneratorAnalysis:The project is a compile-time annotation using the annotation, i.e. @retention (Retentionpolicy.class)@inherited annotations are not used at the same time, so add @parcelable on both the parent and subclass that need to be serializedRefer to Readme.md belowParcelablegenerator IntroductionParcelablegenerator can convert any object to the Pa
android.os.Bundle; import android.os.Parcelable; public class Test extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent i = getIntent(); Person p = i.getParcelableExtra("yes"); System.out.println("---->"+p.name); System.out.println("---->"+p.map.size()); } }
Activity sent
import java.util.HashMap; import android.app.Activi
Bundle. putParcelable can be used to transmit objects, but the class of this object must implement the Parcelable interface.
The following is a simple example of passing objects between activities.
Parcel serializes parameters, and serializes class objects into a binary stream in full bits to improve transmission efficiency.
Parcelable class. The main class, that is, the class of the object to be transmi
Android master path: Serializable and Parcelable, two methods of Intent passing objects in Android
In Android, two methods are passed: Serializable and Parcelable.
Serializable is supported by J2SE. Parcelable is unique to Android.
Use Cases and differences:
1) when using memory, Parcelable has higher performance than
to read the book object from the intent.Third, the principle of parcelable underlying serializationAs you can see from the above example, the serialization of parcelable is cumbersome to use. However, this is a good way to be efficient, because the parcelable serialization process is the native of the underlying memory operation.Detailed JNI and the underlying m
at how to implement the Parcelable interface.To serialize an object by implementing the Parcelable interface:1, realize parcelable interface.2, and implement the public Parcelable interfacevoid Writetoparcel (Parcel dest, int flags) method.3. A custom type must contain a static member named Creator, which requires the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.